package com.demo.service.impl;

import com.demo.entity.Student;
import com.demo.entity.StudentExample;
import com.demo.repository.StudentRepository;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentRepository studentRepository;
    @Override
    public String Login(Integer stuId, String password) {
        StudentExample studentExample=new StudentExample();
        studentExample.createCriteria().andStuIdEqualTo(stuId).andPasswordEqualTo(password);
        //List<Student> students = studentRepository.selectAll(stuId,password);
        List<Student> students = studentRepository.selectByExample(studentExample);
        if(students.isEmpty()){
            return "学号或者密码错误";
        }
        return "登录成功";
    }

    @Override
    public List<Student> selectSelf(Integer stuId) {
        StudentExample studentExample=new StudentExample();
        studentExample.createCriteria().andStuIdEqualTo(stuId);
        List<Student> students = studentRepository.selectByExample(studentExample);
        return students;
    }
}
